package mytest.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

import mytest.controller.base;

public class LoginFilter implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse rsp,
			Object arg2) throws Exception {
		String token = req.getHeader("token");
		String projectid = req.getHeader("projectid");
		String url = req.getRequestURI();
		if (req != null && "OPTIONS".equals(req.getMethod())) {
			return true;
		}
		if (url.contains("/login") || url.contains("/logout") || url.contains("/jenkins/") || url.contains("/admin/") || url.contains("/project/list") || url.contains("/project/add")) {
			return true;
		}
		if (token == null || token.equals("") || projectid == null || projectid.equals("")) {
			return false;
		}
		Response response = base.check(token, projectid);
		if (response != null) {
			return false;
		}
		return true;
	}
	

}
